package com.cdgc.web.controller;

import com.cdgc.web.pojo.Gys;
import com.cdgc.web.service.GysService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
public class GysController {
    @Autowired
    private GysService gysService;
    @RequestMapping("/queryAllGys")
    public ModelAndView queryAllGys(){
        List<Gys> gysList = gysService.queryAllGys();
        ModelAndView mv = new ModelAndView();
        mv.addObject("gysList",gysList);
        mv.setViewName("gystable");
        return mv;
    }
    @RequestMapping("/addNewGys")
    public String addNewGys(Gys gys){
        gysService.addNewGys(gys);
        return "redirect:/queryAllGys";
    }
    @RequestMapping("/deleteGysById")
    public String deleteGysById(Integer id){
        gysService.deleteGysById(id);
        return "redirect:/queryAllGys";
    }
    @RequestMapping("/toUpdateGysById")
    public ModelAndView toUpdateGysById(Integer id){
        Gys gys = gysService.queryGysById(id);
        ModelAndView mv = new ModelAndView();
        mv.addObject("gys",gys);
        mv.setViewName("UpdateGys");
        return mv;
    }
    @RequestMapping("/UpdateGys")
    public String UpdateGys(Gys gys){
        gysService.UpdateGys(gys);
        return "redirect:/queryAllGys";
    }
}
